const crypto = require("crypto");   // Node 自带API 
const keys = "WH2107daydayupyyds";   //   abc123 ==>  WH2105daydayupyydsabc123   密钥 

// 加密函数  aes  data 需要加密的字段 
function aesEncrypt(data, key) {
    key = key || keys;
    const cipher = crypto.createCipher('aes192', key);
    var crypted = cipher.update(data, 'utf8', 'hex');
    crypted += cipher.final('hex');
    return crypted;  // 密文  
}

// 解密 
function aesDecrypt(encrypted, key) {
    key = key || keys;
    const decipher = crypto.createDecipher('aes192', key);
    var decrypted = decipher.update(encrypted, 'hex', 'utf8');
    decrypted += decipher.final('utf8');
    return decrypted;  // 明文 
}

exports.aesEncrypt = aesEncrypt;   // 加密
exports.aesDecrypt = aesDecrypt;   // 解密
exports.keys = keys;        // 密钥 

// md5 
// crypto 